package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *srv.UserListRequest) (*srv.UserListResponse, error) {
	// todo: add your logic here and delete this line

	var user []mysql.User
	mysql.DB.Where("state = ?", in.State).Find(&user)
	var lists []*srv.UserList
	for _, m := range user {
		list := srv.UserList{
			Userid:   int64(m.ID),
			Tel:      m.Tel,
			Password: m.Password,
			State:    int64(m.State),
		}
		lists = append(lists, &list)
	}

	return &srv.UserListResponse{List: lists}, nil
}
